import json
import os


def find_mac(file_path, macs):
    # print("===>",file_path)
    # print("===>",macs)
    list1 = []
    with open(file_path, 'r') as f:
        try:
            dices = json.load(f)
        except Exception:
            return []
        # print("===>",dices)
        gw = dices[0]
        for dic in dices:
            if dic['mac'] in macs:
                list1.append({'path': file_path, 'gw': gw, 'gps': dic})
    return list1


def walk_all(macs):
    list2 = []
    for root, dirs, files in os.walk("./log"):
        for name in files:
            list2 += find_mac(os.path.join(root, name), macs)

    return list2